package inf.coach.mobile;

import java.util.Locale;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;

public class MainMenu extends Activity {
	
	public static EditText lat = null;
	public static EditText lon = null;
	public static long userid = 0;
	
	private CheckBox verkehr;
	private CheckBox gesundheit;
	private CheckBox essen_und_trinken;
	private CheckBox bank_und_post;
	private CheckBox edu;

	private Button suche_250;
	private Button suche_500;
	
	
	
	 public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.mainmenu);
//	        setTitle("Menu page,please select the option you want");  /** English. */ 
	        setTitle("Suche Seite, Bitte wählen Sie die Kategorie ");  /** German. */

	        
			Bundle bunde = this.getIntent().getExtras();
			userid = bunde.getLong("userid");
			
			verkehr= (CheckBox)findViewById(R.id.checkBox_Verkehr) ;
			gesundheit= (CheckBox)findViewById(R.id.checkBox_Gesundheit) ;
/*			einkauf= (CheckBox)findViewById(R.id.checkBox_Einkauf) ;*/
			essen_und_trinken= (CheckBox)findViewById(R.id.checkBox_Essen_und_Trinken) ;
			bank_und_post= (CheckBox)findViewById(R.id.checkBox_Bank_und_Post) ;
			edu= (CheckBox)findViewById(R.id.checkBox_Sonstiges) ;
			suche_250= (Button)findViewById(R.id.Button_Suchen) ;
			suche_500=(Button)findViewById(R.id.button_Suchen_500) ;
			
			suche_250.setOnClickListener(new Button.OnClickListener() {
	        	
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					if(!verkehr.isChecked() && !gesundheit.isChecked() && !essen_und_trinken.isChecked()&& !bank_und_post.isChecked()&& !edu.isChecked() )
					{
						message.show(MainMenu.this, "Fehler",
								"Bitte wählen Sie mindestens eine Kategorie");
					}
					else{
					Location loc = locationinfo.getLocation(MainMenu.this);

					try {
						if (loc != null) {

							double lat = loc.getLatitude();
							double lon = loc.getLongitude();
							System.out.println(lat+"/"+lon);

							// send the parameter to the annnotation seit
							Intent intent = new Intent();

							intent.setClass(MainMenu.this, pois.class);

							Bundle bundle = new Bundle();

							bundle.putLong("userid", userid);
							bundle.putDouble("lat", lat);
							bundle.putDouble("lon", lon);
							bundle.putInt("dis", 250);
							bundle.putBoolean("verkehr", verkehr.isChecked());
							bundle.putBoolean("gesundheit", gesundheit.isChecked());
							bundle.putBoolean("essen_und_trinken", essen_und_trinken.isChecked());
							bundle.putBoolean("bank_und_post", bank_und_post.isChecked());
							bundle.putBoolean("sonstiges", edu.isChecked());							
							intent.putExtras(bundle);
							startActivity(intent);

						} 
						else {
							message.show(MainMenu.this, "Fehler",
									"Keine GPS Daten !");
							//mTts.speak("Information Window, Error,No Location Data,Ok button", TextToSpeech.QUEUE_FLUSH, null);

							lon.setText("");
							lat.setText("");

						}
					} catch (Exception e) {
						e.printStackTrace();
					}

				}
				}

			});
		
			suche_500.setOnClickListener(new Button.OnClickListener() {
	        	
				public void onClick(View arg0) {
					// TODO Auto-generated method stub
					if(!verkehr.isChecked() && !gesundheit.isChecked() && !essen_und_trinken.isChecked()&& !bank_und_post.isChecked()&& !edu.isChecked() )
					{
						message.show(MainMenu.this, "Fehler",
								"Bitte wählen Sie mindestens eine Kategorie");
					}
					else{
					Location loc = locationinfo.getLocation(MainMenu.this);

					try {
						if (loc != null) {

							double lat = loc.getLatitude();
							double lon = loc.getLongitude();
							System.out.println(lat+"/"+lon);

							// send the parameter to the annnotation seit
							Intent intent = new Intent();

							intent.setClass(MainMenu.this, pois.class);

							Bundle bundle = new Bundle();

							bundle.putLong("userid", userid);
							bundle.putDouble("lat", lat);
							bundle.putDouble("lon", lon);
							bundle.putInt("dis", 500);
							bundle.putBoolean("verkehr", verkehr.isChecked());
							bundle.putBoolean("gesundheit", gesundheit.isChecked());
							bundle.putBoolean("essen_und_trinken", essen_und_trinken.isChecked());
							bundle.putBoolean("bank_und_post", bank_und_post.isChecked());
							bundle.putBoolean("sonstiges", edu.isChecked());							
							intent.putExtras(bundle);
							startActivity(intent);

						} 
						else {
							message.show(MainMenu.this, "Fehler",
									"Keine GPS Daten !");
							//mTts.speak("Information Window, Error,No Location Data,Ok button", TextToSpeech.QUEUE_FLUSH, null);

							lon.setText("");
							lat.setText("");

						}
					} catch (Exception e) {
						e.printStackTrace();
					}

				}
				}

			});
	        
	        
	 }  
	   
	 OnKeyListener onKey=new OnKeyListener() {  
	    
	   
	 public boolean onKey(View v, int keyCode, KeyEvent event) {  
	   
	 // TODO Auto-generated method stub  
	   
	 if(keyCode == KeyEvent.KEYCODE_ENTER){  
	   
	 InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);  
	   
	 if(imm.isActive()){  
	   
	 imm.hideSoftInputFromWindow(v.getApplicationWindowToken(), 0 );  
	   
	 }  
	   
	 return true;  
	   
	 }  
	   
	 return false;  
	   
	 }  
	   
	 };  
	 
	 protected void dialoggoback() { 
	        AlertDialog.Builder builder = new Builder(MainMenu.this); 
	        builder.setMessage("Möchten Sie nach Login-Seite gehen ?"); 
	        builder.setTitle("Information"); 
	        builder.setPositiveButton("ok", 
	                new android.content.DialogInterface.OnClickListener() { 
	                    @Override 
	                    public void onClick(DialogInterface dialog, int which) { 
	                        dialog.dismiss(); 
	                        MainMenu.this.finish(); 
	                    }

	                }); 
	        builder.setNegativeButton("abbrechen", 
	                new android.content.DialogInterface.OnClickListener() { 
	                    @Override 
	                    public void onClick(DialogInterface dialog, int which) { 
	                        dialog.dismiss(); 
	                    } 
	                }); 
	        builder.create().show(); 
	    } 
	    @Override 
	    public boolean onKeyDown(int keyCode, KeyEvent event) { 
	        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) { 
	            dialoggoback(); 
	            return false; 
	        } 
	        return false; 
	    }
	    
	
	        
}


